package cn.iborder.core;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import javax.servlet.http.HttpSession;
import javax.websocket.Session;

import com.jfinal.kit.Prop;
import com.jfinal.kit.PropKit;

/**
 * 资源池
 * @author iborder
 *
 */
public class ResPool {
	private static final ResMap resPoolMap;
	//公共配置资源池
	private static final ResMap configPoolMap;
	//用户资源池
	private static final ResMap userPoolMap;
	
	private ResPool() {}
	
	static{
		resPoolMap = new ResMap();
		configPoolMap = new ResMap();
		userPoolMap = new ResMap();
		resPoolMap.put("config", configPoolMap);
		resPoolMap.put("user", userPoolMap);
	}
	
	//获取公共配置资源池
	public static ResMap getConfigPool() {
		return configPoolMap;
	}
	
	//获取当前用户资源池
	public static ResMap getUserPool(Session Session) {
		ResMap resMap = (ResMap) userPoolMap.get(Session);
		if (resMap == null) {
			resMap = new ResMap();
		}
		return resMap;
	}
	
	public static void initConfig() {
		configPoolMap.clear();
		Prop prop = PropKit.use("config.properties");
		Properties properties = prop.getProperties();
		for(Object key:properties.keySet()){
			configPoolMap.put(key.toString(), properties.getProperty(key.toString()));
		}
	}
}
